/*
 * Copyright (c) 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.snj.visangedu.calendar;

import java.io.IOException;

import android.os.AsyncTask;

import com.google.api.services.calendar.Calendar.Calendars.Insert;
import com.google.api.services.calendar.model.Calendar;
import com.snj.visangedu.studytime.StudyPlannerFragment;

/**
 * Asynchronously insert a new calendar with a progress dialog.
 *
 * @author Ravi Mistry
 */
public class GC_Create_Calendar extends AsyncTask<Void, Void, Void> {

  private final Calendar entry;
  private boolean bReturn = true;

  GC_Create_Calendar(Calendar entry) {
    this.entry = entry;
  }

  @Override
  protected void onPreExecute() {
  }

  @Override
  protected Void doInBackground(Void... arg0) {
    try {
      Insert insert = StudyPlannerFragment.Instance.client.calendars().insert(entry);

      insert.setFields("id,summary");
      Calendar calendar = insert.execute();

    } catch (IOException e) {
      bReturn = false;
    } catch (Exception e) {
      bReturn = false;
    } finally {
    }
    return null;
  }

  @Override
  protected void onPostExecute(Void result) {
    AsyncManager.Instance.CreateWorkCalendarComplete(bReturn);
  }
}
